package com.zretc.blog.controller;

import com.zretc.api.pojo.Bookmark;
import com.zretc.blog.service.BookmarkService;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/blog")
public class BookmarkController {
    @Autowired
    BookmarkService bookmarkService;
    @RequestMapping("/addBookmark")
    public RespResult addBookmark(@RequestBody Bookmark bookmark){
        bookmarkService.addBookmark(bookmark);
        return R.success("收藏成功");
    }
    @GetMapping("/getBookmarkByUser")
    public RespResult getBookmarkByUser(Integer userId){
        ArrayList<Bookmark> list = bookmarkService.getBookmarkByUser(userId);
        return R.success(list);
    }

    @GetMapping("/deleteBookmark")
    public  RespResult deleteBookmark(Bookmark bookmark){
        bookmarkService.deleteBookmark(bookmark);
        return R.success("取消收藏成功");
    }
}
